
#ifndef _TTG_PIPELINE_TASK_GATHERERS_
#define _TTG_PIPELINE_TASK_GATHERERS_
#include "Common/Definitions.h"

#include <vector>
#include "Runtime.Low/Services.h"

namespace ttg_internal
{
	namespace pipeline
	{
		//Gatherer, that stores all received tasks.
		class BufferedTaskGatherer :public ttg::services::ITaskScheduler<ttg::services::WiseTask *>
		{
			private:
				std::vector<ttg::services::WiseTask *> tasks;
			public:
				//ITaskScheduler member.
				virtual void split(std::vector<ttg::services::WiseTask *> &tasks,
								   std::vector<ttg::services::WiseTask *> &root_tasks,
								   std::vector<ttg::services::WiseTask *> &child_tasks)
				{
					root_tasks.insert(root_tasks.end(), child_tasks.begin(), child_tasks.end());
					tasks.clear();
				}
				//ITaskScheduler member.
				virtual void addTasks(ttg::structures::Enumerator<ttg::services::WiseTask *> &en)
				{
					while (en.moveNext())
						tasks.push_back(en.current());
				}
				//Returns tasks, that was gathered.
				inline std::vector<ttg::services::WiseTask *> &getGatheredTasks()
				{ return tasks; }
				//Clears all gathered tasks.
				inline void clearGatheredTasks()
				{ tasks.clear(); }
		};
	}
}

#endif
